<?php
/**
 * Created by PhpStorm.
 * User: zhangligang
 * Date: 17/4/22
 * Time: 下午10:18
 */

namespace App\Http\Repository;


use App\Http\Models\User;

class UserRepository implements Repository
{

    private $user;

    private $columns = ['id', 'username', 'role_id', 'nickname', 'avatar', 'phone', 'created_at', 'updated_at'];

    public function __construct(User $user)
    {
        $this->user = $user;

    }

    public function getUserById(int $id, array $columns = [])
    {
        $columns = count($columns) ? $columns : $this->columns;
        return $this->user->find($id, $columns);
    }

    public function getUserByName(string $name, array $columns = [])
    {
        $columns = count($columns) ? $columns : $this->columns;
        return $this->user->where(['username' => $name])->first($columns);
    }


}